<template>
  <div id="role_id">
    <!-- 上层注释以及添加按钮 -->
    <div class="role_id_top">
      <div class="role_id_left">
        注：<br />
        1.增加的新栏目为当前栏目的下一行<br />
        2.修改完的栏目一行需要后提交审批才能生效
      </div>
      <div class="role_id_right">
        <el-button round @click="zengjia">增加</el-button>
      </div>
    </div>
    <!-- 下层渲染表格  -->
    <el-table
      :data="role_list"
      style="width: 100%; margin-bottom: 20px; margin-top: 20px"
      row-key="id"
      border
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="编号"> </el-table-column>
      <el-table-column prop="rolename" label="角色名称"> </el-table-column>
      <el-table-column label="状态" prop="status" v-slot="$s" width="155">
        <template>
          <el-button round size="mini" type="success" v-if="$s.row.status == 1">
            正常
          </el-button>
        </template>
        <template>
          <el-button round size="mini" type="danger" v-if="$s.row.status == 0">
            禁用
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" v-slot="roleS">
        <template>
          <el-button round class="xiugai" type="warning" @click="xiugai(roleS.row)">修改</el-button>
        </template>
        <template>
          <el-button
            round
            class="shanchu"
            type="danger"
            @click="remove(roleS.row.id)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <addrole :isShow="isShow" @chongqi="chongqi" ref='xiugaishuju'></addrole>
  </div>
</template>

<script>
import { mapActions, mapState } from "vuex";
import addrole from "../components/addrole.vue";
export default {
  components: { addrole },
  created() {
    this.RoleActions();
  },
  computed: {
    ...mapState({ role_list: (state) => state.RoleStore.role_list }),
  },
  methods: {
    // 接收到子组件传输过来的参数,调用方法,刷新页面数据
    chongqi() {
      this.RoleActions();
    },
    zengjia() {
      this.isShow.sta = true;
    },
    //用户点击修改,显示模态框
    xiugai(obj){
      this.isShow.sta=true;
      this.$refs.xiugaishuju.xiugaishujus(obj)
    },
    // 用户点击删除,会删除当前行数据
    remove(id) {
      this.$confirm("此操作将永久删除这行数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
          this.$http.post("/api/roledelete", { id }).then((res) => {
            if (res.code == 200) {
              this.RoleActions();
            }
          });
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        }).catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    ...mapActions("RoleStore", ["RoleActions"]),
  },
  data() {
    return {
      isShow: { sta: false },
    };
  },
};
</script>

<style>
#role_id .role_id_top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#role_id .role_id_top .role_id_left {
  font-size: 12px;
  color: #c4c4c4;
}
#role_id .role_id_top .role_id_right button {
  height: 10px;
  line-height: 2px;
  font-size: 12px;
  color: #ffa998;
}
#role_id .xiugai,
#role_id .shanchu {
  height: 10px;
  line-height: 2px;
}
</style>